package cn.edu.xjtu.android.emoji_warfare_android.game.widget;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import cn.edu.xjtu.android.emoji_warfare_android.engine.entity.Entity;
import cn.edu.xjtu.android.emoji_warfare_android.engine.shape.Rectangle;
import cn.edu.xjtu.android.emoji_warfare_android.game.Config;
import cn.edu.xjtu.android.emoji_warfare_android.game.hero.Player;

/**
 * ScoreBar<br>
 * 积分板
 * 
 * @author wyyf
 *
 */
public class ScoreBar extends Entity {

    /**
     * 得分
     */
    public int score;
    /**
     * 生命
     */
    public int life;
    /**
     * 模式
     */
    public String mode;

    Player player;

    public ScoreBar(Player p) {
        super(new Rectangle(0, 0, Config.screenWidth, 65));
        this.score = 0;
        player = p;
        life = 0;
    }

    /**
     * @author wyyf
     */
    @Override
    public boolean onDraw(Canvas canvas) {
        // 底色
        p.setColor(Color.argb(64, 0, 0, 255));
        Rectangle outline = (Rectangle) this.outline;
        canvas.drawRect(outline.x1, outline.y1, outline.x2, outline.y2, p);
        p.reset();

        // 文字
        p.setColor(Color.argb(255, 255, 255, 0));
        p.setTextSize(45);
        canvas.drawText(
                String.format((life < 0) ? "Score: %d Level: %d Life: Death Hp: %d Mode: "
                        : "Score: %d Level: %d Life: %d Hp: %d Mode: ", score, player.level, life, player.hp) + mode,
                0, outline.y2 - 10, p);
        p.reset();

        return false;
    }

    static Paint p;
    static {
        p = new Paint();
    }
}
